package com.metrics.ctrls.imp;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletOutputStream;

import com.database.objects.*;
import com.metrics.ctrls.IGraphicCtrl;
import com.metrics.extractors.*;
import com.metrics.formatters.*;
import com.metrics.graphics.*;
import com.metrics.objects.*;

public class GraphicCtrl implements IGraphicCtrl {

	private static final long serialVersionUID = -7725498171124787235L;

	private MetricExtractorMap metricExtractorMap;

	private GraphicGeneratorMap graphicGeneratorMap;

	private TimeFormatterMap timeFormatterMap;

	@Override
	public void generateGraphic(ServletOutputStream out, List<Developer> developers, Options options) throws IOException {
		Metric metric = options.getMetric();
		Graphic graphic = options.getGraphic();
		Type type = options.getType();
		Status status = options.getStatus();
		String start = options.getStart();
		String finish = options.getFinish();
		Time time = options.getTime();

		MetricExtractor extractor = metricExtractorMap.get(metric);
		GraphicGenerator graphicGenerator = graphicGeneratorMap.get(graphic);
		TimeFormatter timeFormatter = timeFormatterMap.get(time);

		graphicGenerator.generate(out, developers, extractor, type, status, start, finish, timeFormatter);
	}

	public void setMetricExtractorMap(MetricExtractorMap metricExtractorMap) {
		this.metricExtractorMap = metricExtractorMap;
	}

	public void setGraphicGeneratorMap(GraphicGeneratorMap graphicGeneratorMap) {
		this.graphicGeneratorMap = graphicGeneratorMap;
	}

	public void setTimeFormatterMap(TimeFormatterMap timeFormatterMap) {
		this.timeFormatterMap = timeFormatterMap;
	}

}